home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FindSysFolder.c
-
- Contains: Here's a snippet. It returns the vRefNum and DirID of the System Folder.
- It does it the right way under both 6.0 and 7.0.
-
- Written by:
-
- Copyright: Copyright © 1984-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 8/5/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- #include <Types.h>
- #include <stdio.h>
- #include <OSUtils.h>
- #include <Files.h>
- #include <Gestalt.h>
- #include <Folders.h>
- #define BTstQ(arg, bitnbr) (arg & (1 << bitnbr))
-
- /*
- FindSysFolder returns the (real) vRefNum, and the DirID of the current
- system folder. It uses the Folder Manager if present, otherwise it falls
- back to SysEnvirons. It returns zero on success, otherwise a standard
- system error.
- */
- OSErr FindSysFolder(short *fondVRefNum,long *foundDirID);
-
- void main()
- {
- short vRefNum;
- long DirID;
- FindSysFolder(&vRefNum,&DirID);
- printf("The System Folder is VRefNum:%i DirID:%i\n",vRefNum,DirID);
- }
- OSErr FindSysFolder(short *foundVRefNum, long *foundDirID)
- {
- long gesResponse;
- SysEnvRec envRec;
- WDPBRec myWDPB;
- unsigned char volName[34];
- OSErr err;
-
- *foundVRefNum = 0;
- *foundDirID = 0;
-
- /* Does Folder Manager exist? */
- if (!Gestalt(gestaltFindFolderAttr, &gesResponse) &&
- BTstQ(gesResponse, gestaltFindFolderPresent)) {
- err = FindFolder(kOnSystemDisk, kSystemFolderType,
- kDontCreateFolder, foundVRefNum, foundDirID);
- } else { /* Gestalt can't give us the answer, so we resort to SysEnvirons */
- if (!(err = SysEnvirons (curSysEnvVers, &envRec))) {
- myWDPB.ioVRefNum = envRec.sysVRefNum;
- volName[0] = '\0'; /* Zero volume name */
- myWDPB.ioNamePtr = volName;
- myWDPB.ioWDIndex = 0;
- myWDPB.ioWDProcID = 0;
- if (!(err = PBGetWDInfo(&myWDPB, 0))) {
- *foundVRefNum = myWDPB.ioWDVRefNum;
- *foundDirID = myWDPB.ioWDDirID;
- }
- }
- }
- return (err);
- }
- //======================================================================
-
-